﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;


namespace MinaspetroLibrary.ManualPack
{

    [Serializable()]
    public class ManualChildInfo : Csla.ReadOnlyBase<ManualChildInfo>
    {
        #region Business Properties and Methods

        private Guid _id = Guid.NewGuid();

        private String _titulo = String.Empty;

        private String _resumo = String.Empty;

        private String _descricao = String.Empty;

        private String _arquivo = String.Empty;

        private String _publicar = String.Empty;

        private DateTime _dataPublicacao = DateTime.Now;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Titulo
        {
            get
            {
                return _titulo;
            }
        }

        public string Resumo
        {
            get
            {
                return _resumo;
            }
        }

        public string Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public string Arquivo
        {
            get
            {
                return _arquivo;
            }
        }

        public string ArquivoString
        {
            get
            {
                if (_arquivo.Contains("_"))
                    return _arquivo.Substring(_arquivo.IndexOf("_") + 1);
                return _arquivo;
            }
        }

        public DateTime DataPublicacao
        {
            get
            {
                return _dataPublicacao;
            }
        }

        public string DataPublicacaoShortString
        {
            get
            {
                return _dataPublicacao.ToString("dd/MM/yyyy");
            }
        }

        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static ManualChildInfo GetManualChildInfo(SafeDataReader dr)
        {
            return new ManualChildInfo(dr);
        }

        private ManualChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region DataPublicacao Access

        #region DataPublicacao Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _titulo = dr.GetString("Titulo");
            _resumo = dr.GetString("Resumo");
            _descricao = dr.GetString("Descricao");
            _arquivo = dr.GetString("Arquivo");
            _publicar = dr.GetString("Publicar");
            _dataPublicacao = dr.GetDateTime("DataPublicacao");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //DataPublicacao Access - Fetch
        #endregion //DataPublicacao Access
    }
}
